<?php
/**
 *	[TWCMS] (C)2012 TongWang Inc.
 *	$Id: theme.class.php 2 2013-04-27 07:14:17Z nanown@qq.com $
 */
defined('IN_TWCMS') || exit('Access Denied');

class theme{
	#读取所有主题
	function getThemeAll() {
		$dir = TWCMS_THEME;
		$theme = array();
		if(is_dir($dir)) {
			if($dh = opendir($dir)) {
				while (($file = readdir($dh)) !== false) {
					$path = $dir.$file;
					if($file!='.' && $file!='..' && filetype($path)=='dir' && is_file($path.'/info.ini') && $infos=file($path.'/info.ini')) {
						$theme[$file] = $this->getThemeInfo($infos);
					}
				}
				closedir($dh);
			}
		}
		return $theme;
	}

	#读取主题信息
	function getThemeInfo($infos) {
		$array = array();
		foreach($infos as $arr) {
			$vals = _trim(explode('=', $arr));
			if($vals[0] == 'description') {
				$array[$vals[0]] = strip_tags($vals[1], '<br>');
			}elseif(in_array($vals[0], array('name', 'version', 'update', 'author', 'authorurl'))) {
				$array[$vals[0]] = strip_tags($vals[1]);
			}
		}
		return $array;
	}
}